<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
{% load staticfiles %}
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>天天生鲜-登录</title>
    <link rel="stylesheet" type="text/css" href="{% static 'css/reset.css' %}">
	<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">
    <script src="{% static 'js/jquery-1.12.4.min.js' %}"></script>
    <script>
        $(function () {
            $('#btnLogin').click(function () {
                // 1.获取用户名和密码
                username = $('#username').val()
                password = $('#pwd').val()
                csrf = $('input[name="csrfmiddlewaretoken"]').val()
                remember = $('input[name="remember"]').is(':checked')
                //alert(remember)
                // 2.发起一个ajax请求，携带参数username,password,csrfmiddlewaretoken
                params = {'username':username, 'password':password,
                    'csrfmiddlewaretoken':csrf, 'remember':remember}
                $.post('{% url 'login_check' %}', params, function (data) {
                    // 返回的数据格式:
                    // 1.用户名密码错误 {'res':0}
                    // 2.用户名密码正确 {'res':1}
                    if (data.res == 0){
                        $('#username').next().show().text('用户名或密码错误')
                    }
                    else
                    {
                        // 跳转到首页 /
                        //location.href = '/'
                        location.href = data.next
                    }
                })
            })
        })
    </script>
</head>
<body>
	<div class="login_top clearfix">
		<a href="{% url 'home_page' %}" class="login_logo"><img src="{% static 'images/logo02.png' %}"></a>
	</div>

	<div class="login_form_bg">
		<div class="login_form_wrap clearfix">
			<div class="login_banner fl"></div>
			<div class="slogan fl">日夜兼程 · 急速送达</div>
			<div class="login_form fr">
				<div class="login_title clearfix">
					<h1>用户登录</h1>
					<a href="{% url 'register' %}">立即注册</a>
				</div>
				<div class="form_input">
{#					<form method="post" action="/user/login_check/">#}
                        {% csrf_token %}
						<input type="text" id="username" class="name_input" value="{{ username }}" placeholder="请输入用户名">
						<div class="user_error">输入错误</div>
						<input type="password" id="pwd" class="pass_input" placeholder="请输入密码">
						<div class="pwd_error">输入错误</div>
						<div class="more_input clearfix">
							<input type="checkbox" name="remember">
							<label>记住用户名</label>
							<a href="#">忘记密码</a>
						</div>
						<input type="button" id="btnLogin" value="登录" class="input_submit">
{#					</form>#}
				</div>
			</div>
		</div>
	</div>

	<div class="footer no-mp">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	
</body>
</html>